package com.ysq.start;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import com.ysq.frame.KeyCommand;
import com.ysq.frame.MainPanel;

/**
 * 启动类
 * @author Administrator
 *
 */
public class ProgramRun extends JFrame{
	private static final long serialVersionUID = 1L;
	
	public static final int frameWidth = 520;
	public static final int frameHeight = 460;
	
	Toolkit tollKit;
	Dimension dimen;
	
	public ProgramRun(String title){
		super(title);
		tollKit = Toolkit.getDefaultToolkit();
		dimen = tollKit.getScreenSize();
		this.setSize(frameWidth,frameHeight);
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭
		this.setResizable(false);//不可改变大小
		this.setLocation((dimen.width - frameWidth)/2, (dimen.height - frameHeight)/2);
		
		//panel
		MainPanel mainPanel = new MainPanel();
		this.add(mainPanel);
		
		//添加监听
		KeyListener listener = new KeyCommand(mainPanel);
		this.addKeyListener(listener);
		
		this.setVisible(true);
	}
	
	public static void main(String[] args) {
		new ProgramRun("贪吃蛇");
	}
}
